package  com.hq.fxh.No0_ChengQu.Fragment;

/**
 * Created by admin on 2017/8/3.
 */

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hq.fxh.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/7/25 0025.
 */
public class HomeFragment extends BaseFragment {
    private ArrayList<String> mDatas;
     private RecyclerView mListView;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }




    @Override
    public int getLayoutId() {
        return R.layout.list_layout;
    }

    @Override
    protected void findView(View view) {
        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeLayout);
        mListView = (RecyclerView) view.findViewById(R.id.list_view);
        mListView.setLayoutManager(new LinearLayoutManager(mContext));
        mListView.setAdapter(new ListAdapter());
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mSwipeRefreshLayout.setRefreshing(false);
            }
        });
    }

    @Override
    protected void initData() {

    }

    public static HomeFragment newInstance() {

        Bundle args = new Bundle();

        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }



    public void initData(char a, char b) {
        mDatas = new ArrayList<>();
        for (int i = a; i < b; i++) {
            mDatas.add("" + (char) i);
        }
    }

    class ListAdapter extends RecyclerView.Adapter<ListAdapter.MyViewHolder> {
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item, parent, false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            try {
                holder.tv.setText(mDatas.get(position));
            }catch (Exception  e){}
        }

        @Override
        public int getItemCount() {
            return mDatas==null?0:mDatas.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            TextView tv;

            public MyViewHolder(View view) {
                super(view);
                tv = (TextView) view.findViewById(R.id.id_num);
            }
        }
    }
}